package com.ibeeking.found.msg.api.feign.fallback;

import com.ibeeking.found.msg.api.common.dto.KfAccountDTO;
import com.ibeeking.found.msg.api.common.dto.KfServicerDTO;
import com.ibeeking.found.msg.api.feign.MsgCopBFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class MsgCopBFeignFallbackFactory implements FallbackFactory<MsgCopBFeignClient> {
    @Override
    public MsgCopBFeignClient create(Throwable throwable) {
        return new MsgCopBFeignClient() {
            @Override
            public ResponseResult<KfAccountDTO> queryDefaultKfAccount() {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，获取缺省客服账号信息失败。" + throwable.getMessage(), null);
            }

            @Override
            public ResponseResult<KfServicerDTO> queryDefaultKfServicer() {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，获取缺省客服接待人员信息失败。" + throwable.getMessage(), null);
            }
        };
    }
}
